package com.gzdh.dishrecognition.emu;

import com.gzdh.dishrecognition.Test_lib;

public enum CardSectorPassEmus {

    SY(0, "动态密码（省医）"),
    GD(1, "固定密码"),
    FY(2, "妇婴密码"),
    TY(3, "通用密码"),
    DH(4, "大宏密码");
    public static final byte[] DH_CARD_PWD = {(byte) 0x07, (byte) 0x06, (byte) 0x10, (byte) 0x07, (byte) 0x06, (byte) 0x10};
    public static final byte[] GD_CARD_PWD = {(byte) 0x3d, (byte) 0x48, (byte) 0x5a, (byte) 0x3b, (byte) 0xef, (byte) 0x01};
    public static final byte[] FY_CARD_PWS = {(byte) 0x1B, (byte) 0x24, (byte) 0x3A, (byte) 0x5D, (byte) 0x4C, (byte) 0x3E};
    private int value;

    private String name;

    private byte[] password;

    private CardSectorPassEmus(int v, String name) {
        this.value = v;
        this.name = name;
    }

    // 根据value返回枚举类型,主要在switch中使用
    public static CardSectorPassEmus getByValue(int value) {
        for (CardSectorPassEmus code : values()) {
            if (code.getValue() == value) {
                return code;
            }
        }
        return null;
    }

    public int getValue() {
        return value;
    }

    public void setValue(int value) {
        this.value = value;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public byte[] getPassword() {
        switch (value) {
            case 1:
                return GD_CARD_PWD;
            case 2:
                return FY_CARD_PWS;

            case 4:
                return DH_CARD_PWD;
        }
        return password;
    }

    public byte[] getPassword(byte[] cardsnByte) {
        switch (value) {
            case 0:
                return Test_lib.getStrA(cardsnByte);
            case 1:
                return GD_CARD_PWD;
            case 2:
                return FY_CARD_PWS;

            case 4:
                return DH_CARD_PWD;
        }
        return password;
    }

    public void setPassword(byte[] password) {
        this.password = password;
    }
}
